package io.finer.erp.jeecg.approve.service.impl;

import io.finer.erp.jeecg.approve.entity.ApproveFlowNode;
import io.finer.erp.jeecg.approve.entity.ApproveMember;
import io.finer.erp.jeecg.approve.mapper.ApproveFlowNodeMapper;
import io.finer.erp.jeecg.approve.service.ApproveFlowNodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.finer.erp.jeecg.approve.service.ApproveMemberService;
import io.finer.erp.jeecg.approve.vo.ApproveFlowNodePage;
import io.finer.erp.jeecg.approve.vo.ApproveFlowNodewithMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 审批流节点 服务实现类
 * </p>
 *
 * @author yaoyifan
 * @since 2021-04-14
 */
@Service
public class ApproveFlowNodeServiceImpl extends ServiceImpl<ApproveFlowNodeMapper, ApproveFlowNode> implements ApproveFlowNodeService {

    @Autowired
    ApproveMemberService approveMemberService;

    @Override
    @Transactional
    public void saveMain(ApproveFlowNode approveFlowNode, List<ApproveMember> approveMemberList) {
        this.baseMapper.insert(approveFlowNode);
        if (approveMemberList != null && approveMemberList.size() > 0) {
            for(ApproveMember entity: approveMemberList){
                entity.setNodeId(approveFlowNode.getId());
            }
            approveMemberService.saveBatch(approveMemberList);
        }
    }

    @Override
    public List<ApproveFlowNodewithMember> selectApproveFlowNodewithMemberByMid(String mid) {
        return this.baseMapper.selectApproveFlowNodewithMemberByMid(mid);
    }
}
